<!-- 选择收货地址 -->
<template>
    <div class="address-container">
        <div class="current-month" @click="chooseMonth">
            <h2>{{year}}年{{month}}月<img src="~assets/images/dealer/arrowdown.png" /></h2>
        </div>
        <div class="scroll-area">
            <cube-scroll v-if="historyList.length > 0">
                <div class="item" v-for="item in historyList">
                    <div class="avatar">
                        <img src="~assets/images/dealer/diamond2.png" v-if="item.level == 1" />
                        <img src="~assets/images/dealer/star2.png" v-if="item.level == 2" />
                        <img src="~assets/images/dealer/crown2.png" v-if="item.level == 3" />
                    </div>
                    <div class="detail">
                        <h3><strong>{{item.goodsName}}</strong><span>{{item.totalPrice}} CVNT</span></h3>
                        <p><strong>数量:{{item.num}}个 单价:{{item.unitPrice}}cvnt/个</strong><span>{{item.createTime}}</span></p>
                    </div>
                </div>
            </cube-scroll>
            <h3 v-else style="text-align:center;margin-top:30px;font-size:13px;">
              抱歉，当前月暂无兑换记录
            </h3>
        </div>
        <!--支付相关弹框-->
        <!--<div class="mask" v-show="showMask" @click="closeMask($event)">
            <div ref="maskContent">
                <transition name="fade">
                    <div class="general-height shopping-detail" v-if="showMonth">
                        <h3 class="title">兑换记录筛选</h3>
                        <div class="content">

                        </div>
                        <div class="pay-btn">
                            <p @click.stop.prevent="confirmToEdit">确定</p>
                        </div>
                    </div>
                </transition>
            </div>
        </div>-->
        <div @touchmove.prevent><!-- @touchmove.prevent 阻止默认事件，在选择时间时阻止页面也跟着滚动-->
          <mt-datetime-picker
            lockScroll="true"
            ref="datePicker"
            v-model="dateVal"
            type="date"
            year-format="{value}"
            month-format="{value}"
            date-format="{value}"
            @confirm="handleConfirm">
          </mt-datetime-picker>
        </div>
    </div>
</template>

<script>
  import {exchangeList } from 'api/register'
  export default {
    props: [],
    components: {

    },
    data () {
      return {
        dateVal: '',
        showPicker: false,
        year: '',
        month: '',
        currentMonth: '',
        selectedValue: '',
        type: 1,
        isShow: false,
        showMonth: false,
        isIOS: false,
        uid: localStorage.getItem('uid') || window['uid'],
        token: window['token'],
        addrId: 0,
        coinType: 3,
        starPhone: '',
        scene: 'transfer',
        current: 0,
        showResult: false,
        showMask: false,
        sign: '',
        historyList: []
      }
    },
    beforeRouteEnter(to, from, next) {
      next((vm) => {
        vm.getCurrentMonth();
        vm.detectOS();
        let query = to.query;
        Object.assign(vm, query);
        vm.uid = query.uid;
        vm.token = query.token;
        vm.getExchangeList();


      })
    },
    created() {

    },
    mounted(){

    },
    computed: {


    },
    watch: {

    },
    methods: {
      getExchangeList() {
        exchangeList(this.currentMonth).then((data) => {

          if (data.status && data.status == 1) {
            if (data.data && data.data.length > 0) {
              this.historyList = data.data;
            }
            if (!data.data || data.data == null || data.data.length == 0) {
              this.historyList = [];
            }
          }
        }).catch((err) => {
          this.showToast(err.info, 'warn');
        })
      },
      detectOS() {
        let u = navigator.userAgent;
        // console.log(u);
        this.isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        // console.log(this.isIOS);
      },
      chooseMonthNumber(val) {
        this.monthNum = val;
      },
      handleConfirm(val) {

        // this.currentMonth = this.formatDate(val);
        this.formatDate(val);

      },
      formatDate(secs) {
        let t = new Date(secs);
        let year = t.getFullYear();
        let month = t.getMonth() + 1;
        if (month < 10) {month = '0' + month;}
        this.year = year;
        this.month = month;
        this.currentMonth = year + '-' + month;
        this.getExchangeList();
      },
      chooseMonth() {
        if (this.currentMonth) {
          this.dateVal = this.selectedValue;
        } else {
          this.dateVal = new Date();
        }
        this.$refs['datePicker'].open();
        /*if (!this.formatPicker) {
          this.formatPicker = this.$createDatePicker({
            title: '兑换记录筛选',
            value: new Date(),
            format: {
              year: 'YYYY',
              month: 'MM',
              date: ''
            },
            columnCount: 2,
            onSelect: this.selectHandle,
            onCancel: this.cancelHandle
          })
        }
        this.formatPicker.show();*/
      },
      selectHandle(date, selectedVal, selectedText) {
        console.log(date, selectedVal, selectedText);
        this.year = selectedText[0];
        this.month = selectedText[1];
        this.currentMonth = selectedText[0] + '-' + selectedText[1];
        this.getExchangeList();
        console.log(this.currentMonth);
      },
      cancelHandle() {

      },
      showToast(msg, type) {
        const toast = this.$createToast({
          time: 2000,
          txt: msg,
          type: type
        });
        toast.show();
      },
      getCurrentMonth() {
        let now = new Date();
        let year = now.getFullYear();
        let month = now.getMonth() + 1;
        let date = now.getDate();
        if (month < 10) {
          month = '0' + month;
        }
        if (date < 10) {
          date = '0' + date;
        }
        this.year = year;
        this.month = month;
        this.currentMonth = year + '-' + month;
        this.selectedValue = year + '-' + month + '-' + date;
        console.log(this.currentMonth);
        /*if (type == 'm') {
          return year + '-' + month;
        }*/
      },
      close() {
        this.showMask = false;
      },
      forget() {

      },
      inputEnd() {

      },
      closeMask(ev) {
        if (!this.$refs.maskContent.contains(ev.target)) {
          this.showMask = false;
        }
      },
      confirmToEdit() {

      }
    }
  }
</script>

<style lang="scss" scoped>
  @import 'common/scss/index.scss';
  body,html{
    height:100%;
  }
  .address-container{
    /*height:calc(100% - 88px);*/
    position:relative;
    height:100%;
    background:#fff;
    /*overflow-y:auto;*/
    /*overflow:hidden;*/
  }
  .scroll-area{
    height:calc(100% - 100px);
    /*overflow-y:auto;*/
    .item{
      display:flex;
      .avatar{
        img{
          width:80px;
          height:80px;
          margin:35px 19px 35px 38px;
        }
      }
      .detail{
        flex:1;
        padding-right:38px;
        border-bottom:1px solid #F1F1F1;
        h3{
          display:flex;
          justify-content:space-between;
          margin:39px 0 17px;
          font-size:30px;
          strong{
            color:#1D2858;
          }
          span{
            color:#EDAC1A;
          }
        }
        p{
          display:flex;
          justify-content:space-between;
          font-size:26px;
          color:#71768C;
        }
      }
    }
    .item:last-child{
      .detail{
        border-bottom:0;
      }
    }
  }
  .current-month{
    height:99px;
    line-height:99px;
    padding-left:29px;
    border-bottom:1px solid #e9e9e9;
    color:#202C5B;
    font-size:36px;
    img{
      width:24px;
      height:16px;
      vertical-align:middle;
      margin-left:15px;
    }
  }
  .dealer-info{
    padding-top:30px;
    background:#30344D;
  }
  .dealer-wrapper{
    position:relative;
    z-index:999;
    display:flex;
    justify-content:space-between;
    width:92%;
    height:270px;
    border-radius:14px;
    margin:0 30px 0;
    color:#fff;
    .title{
      width:70.99999%;
      // text-align:center;
      h2{
        display:flex;
        justify-content:space-between;
        align-items:center;
        margin:40px 0 23px;
        strong{
          font-size:36px;
          font-weight:600;
          color:#FFF;
        }
        span{
          width:144px;
          height:50px;
          text-align:center;
          line-height:50px;
          border-radius:25px 0 0 25px;
          font-size:20px;
        }
        .diamond{
          background:rgba(139,143,186,1);
        }
        .star{
          background:rgba(184,131,58,1);
        }
        .crown{
          background:rgba(145,127,198,1);
        }
      }
      p{
        font-size:28px;
        color:#fff;
        opacity:0.6;
      }
      .upgrade-btn{
        width:178px;
        height:54px;
        line-height:54px;
        margin-top:30px;
        text-align:center;
        background:linear-gradient(-90deg,rgba(87,90,133,1),rgba(37,47,74,1));
        border-radius:27px;
        color:#FCE2AE;
        font-size:24px;
      }
    }
    .logo{
      width:28.99999%;
      text-align:center;
      img{
        width:156px;
        height:172px;
        margin-top:38px;
      }
    }
  }













  .member-container{
    width:92%;
    margin:-10px 30px 0;
    padding:0 24px 24px;
    background:#575A85;
    .price-wrapper{
      display:flex;
      .price-detail{
        width:30.99999%;
        margin-right:3.499999%;
        background:rgba(255,255,255,1);
        border:1px solid rgba(232,222,213,1);
        border-radius:8px;
        text-align:center;
        cursor:pointer;
        h4{
          margin:32px 0 18px;
          font-size:30px;
          color:#636363;
          font-weight:600;
        }
        h5{
          font-size:24px;
          color:#EBA74E;
          span{
            font-size:66px;
          }
        }
        p{
          font-size:24px;
          margin:9px 0 11px;
          color:#919191;
        }
        h6{
          height:54px;
          line-height:54px;
          font-size:24px;
          background:#FFF5E7;
          color:#836239;
        }
      }
      .selected{
        background:rgba(255,246,233,1);
        border:1px solid rgba(224,173,101,1);
        h4{
          color:#542B00;
        }
        h5{
          color:#EBA74E;
          span{

          }
        }
        p{
          color:#755125;
        }
        h6{
          background:linear-gradient(-90deg,rgba(245,212,153,1),rgba(230,182,113,1));
          color:#FFF;
        }
      }
      .price-detail:last-child{
        margin-right:0;
      }
    }
    .exchange-btn{
      width:100%;
      height:88px;
      line-height:88px;
      margin-top:24px;
      text-align:center;
      background:linear-gradient(-90deg,rgba(225,179,114,1) 0%,rgba(251,228,169,1) 100%);
      border-radius:44px;
      font-size:36px;
      font-weight:600;
      color:#5B3301;
      cursor:pointer;
    }
  }

  .go-outside-btn{
    display:flex;
    font-size:30px;
    padding:30px 0;
    background:#424459;
    color:#F2F2F8;
    >div{
      width:49.99999%;
      height:40px;
      line-height:40px;
      cursor:pointer;
      text-align:center;
    }
    >div:first-child{
      border-right:1px solid #8B8E9D;
    }
  }
  .contact-wrapper{
    padding:30px;
    background:#F5F5FB;
    .contact-container{
      background:rgba(255,255,255,1);
      box-shadow:0 1px 2px 0 rgba(10,29,87,0.2);
      border-radius:10px;
    }
    .contact-content{
      display:flex;
      height:88px;
      justify-content:space-between;
      align-items:center;
      padding:0 24px;
      border-bottom:1px solid #f5f5f5;
      h3{
        font-size:30px;
      }
      .able{
        color:#202C5B;
      }
      .disable{
        color:#D0D0D0;
      }

      .able-btn{
        width:120px;
        height:54px;
        line-height:54px;
        text-align:center;
        font-size:24px;
        color:#fff;
        background:rgba(23,62,143,1);
        border-radius:27px;
      }
      .edit-able{
        background:rgba(23,62,143,1);
      }
      .edit-disable{
        background:rgba(208,208,208,1);
      }
    }
    .contact-intro{
      padding:20px 42px 24px 24px;
      p{
        font-size:24px;
        line-height:1.75;
      }
      .able{
        color:#71768C;
      }
      .disable{
        color:#D0D0D0;
      }
    }
  }

  .active-ct {
    .content {
      margin: 0 auto;
      width: 77.0666vw;
      height: 87.7333vw;
      margin-bottom: 17px;
      -webkit-overflow-scrolling: touch;
      overflow: auto;
      //pointer-events: all;
      h3{
        text-align:center;
        img{
          vertical-align:middle;
          width:93px;
          height:18px;
        }
        span{
          display:inline-block;
          margin:41px 20px 0;
          font-size:36px;
          font-weight:500;
          color:rgba(255,255,255,1);
          text-shadow:0 2px 2px rgba(51,51,51,0.3);
        }
      }
      .success-wrapper{
        margin-top:94px;
        text-align:center;
        .success-img{
          img{
            width:156px;
            height:172px;
          }
        }
        .success-text{
          h4{
            margin:16px 0 15px;
            font-size:28px;
            color:#464850;
          }
          p{
            font-size:24px;
            color:#9292AA;
          }
        }
        .close-btn{
          img{
            width:370px;
            height:76px;
            margin-top:17px;
            cursor:pointer;
          }
        }
      }

    }
    .diamond{
      background: url("~assets/images/dealer/diamondbg2.png") no-repeat center center;
      background-size: contain;
    }
    .star{
      background: url("~assets/images/dealer/starbg2.png") no-repeat center center;
      background-size: contain;
    }
    .crown{
      background: url("~assets/images/dealer/crownbg2.png") no-repeat center center;
      background-size: contain;
    }
    .close {
      margin: 0 auto;
      width: 38px;
      height: 38px;
      background: url("~assets/images/close.png") no-repeat center center;
      background-size: contain;
    }
  }


  .selected{
    border:1px solid #173E8F;
    /*background:#fff url("~assets/images/choose1.png") no-repeat left top;*/
    background:#fff;
    /*background-size:34px 34px;*/
  }

  /*.next-step{
    position:fixed;
    z-index:9988;
    bottom:0;
    left:0;
    right:0;
    color:#fff;
    height:88px;
    line-height:88px;
    text-align:center;
    background:#173E8F;
    span{
      display:block;
      font-size:28px;
    }
  }*/
  .next-step{
    display:flex;
    color:#fff;
    height:88px;
    line-height:88px;
    align-items:center;
    background:#173E8F;
    span{
      display:block;
      width:100%;
      height:88px;
      line-height:88px;
      font-size:28px;
      text-align: center;
    }
  }
  .add-btn{
    height:150px;
    line-height:150px;
    border:1px solid rgba(201,204,220,1);
    border-radius:10px;
    margin:30px 26px 140px;
    text-align:center;
    color:#1253FC;
    /*padding:10px 0;*/
    img{
      display:inline-block;
      width:36px;
      height:36px;
      vertical-align:middle;
      margin-right:12px;
      margin-top:-2px;
    }
    span{
      display:inline-block;
      vertical-align:middle;
      font-size:30px;
    }
  }

  .mask{
    position:fixed;
    z-index:9991;
    height:100%;
    width:100%;
    top:0;
    bottom:0;
    left:0;
    right:0;
    background:rgba(0, 0, 0, 0.5);

    .general-height{
      /*height: 500px;*/
      height: 67.46vh;
      background:rgba(255,255,255,1);
    }
    .title{
      padding:29px 0 28px;
      font-size:34px;
      border-bottom:1px solid rgba(245,245,245,1);
      color:#202C5B;
      text-align:center;
    }
    .number-group{
      position:absolute;
      z-index:9992;
      bottom:0;
      left:0;
      right:0;
      height:448px;
      >div:first-child{
        border-top:1px solid rgba(245,245,245,1);
      }
      .number-btn{
        display:flex;
        div{
          flex:1;
          height:111px;
          line-height:111px;
          font-size:50px;
          color:#333;
          text-align:center;
          border-bottom:1px solid rgba(245,245,245,1);
          border-right:1px solid rgba(245,245,245,1);
          -webkit-tap-highlight-color:rgba(0,0,0,0.15);
        }
        div:active{
          background:rgba(0,0,0,0.15);
        }
        div:last-child{
          border-right:none;
        }
        .no-num{
          background:#e3e7ee;
          img{
            width:44px;
            height:32px;
            display:block;
            margin:40px auto;
          }
        }
      }
    }
    .shopping-detail{
      position:fixed;
      width:100%;
      bottom:0;
      left:0;
      right:0;

      .content{
        margin:97px 30px 0;
        h2{
          margin-bottom:66px;
          text-align:center;
          font-size:30px;
          color:#202C5B;
          font-weight:600;
          span{
            font-size:72px;
          }
        }
        p{
          display:flex;
          justify-content:space-between;
          margin-top:30px;
          font-size:28px;
          padding-bottom:29px;
          border-bottom:1px solid #ececec;
          span{
            color:#71768C;
          }
          strong{
            color:#202C5B;
          }
        }
        /*p:last-child{
          margin-top:30px;
        }*/
        .wechat{
          input{
            display:block;
            width:100%;
            height:84px;
            line-height:84px;
            border:1px solid rgba(227,227,227,1);
            border-radius:8px;
            text-indent:22px;
            font-size:26px;
            box-shadow:0 0 0 rgba(0,0,0,0);
            -webkit-appearance:none;
            outline:none;
            background:#F6F7F8;
          }
        }
      }
      .result{
        margin-top:97px;
        text-align:center;
        img{
          width:80px;
          height:80px;
          margin-bottom:41px;
        }
        h3{
          margin-bottom:60px;
          font-size:28px;
          color:#202C5B;
        }
        p{
          font-size:28px;
          color:#71768C;
        }
      }
      .pay-btn{
        position:absolute;
        bottom:30px;
        height:84px;
        line-height:84px;
        text-align:center;
        background:rgba(23,62,143,1);
        border-radius:8px;
        color:#fff;
        width:calc(100% - 60px);
        margin:0 30px;
        font-size:32px;
      }
    }
    .pay-password{
      position:fixed;
      width:100%;
      bottom:0;
      left:0;
      right:0;
      .password-wrapper{
        display:flex;
        margin:43px 30px 0;
        height:88px;
        line-height:88px;
        border:1px solid rgba(209,209,209,1);
        border-radius:10px;
        span{
          flex:1;
          text-align:center;
          border-right:1px solid rgba(209,209,209,1);
          strong{
            display:block;
            width:20px;
            height:20px;
            border-radius:50%;
            background:#333;
            margin:34px auto;
          }
        }
        span:last-child{
          border-right:none;
        }
      }
      .forget-password{
        color:#1253FC;
        width:25%;
        padding:12px 0;
        margin:12px auto 0;
        text-align:center;
        font-size:28px;
      }
      .pay-loading{
        position:absolute;
        z-index:9993;
        bottom:0;
        left:0;
        right:0;
        height:calc(100% - 70px);
        background:#fff;
        .paying{
          position:absolute;
          left:50%;
          top:50%;
          transform:translate(-50%, -50%);
          text-align:center;
          font-size:30px;
          color:#4B74E8;
          img{
            display:block;
            width:40px;
            height:40px;
            margin:0 auto 15px;
          }
        }
      }

    }
    .id-check{
      position:fixed;
      width:100%;
      bottom:0;
      left:0;
      right:0;
      .check-title{
        position:relative;
        img{
          position:absolute;
          left:30px;
          top:29px;
          width:34px;
          height:34px;
        }
      }
      .check-content{
        margin-top:32px;
        padding:0 30px;
        p{
          text-align:center;
          color:#202C5B;
          font-size:26px;
          line-height:1.5;
        }
        .sms-input{
          height:84px;
          line-height:84px;
          margin-top:28px;
          input{
            display:inline-block;
            height:84px;
            line-height:84px;
            width:59.9999%;
            text-indent:22px;
            font-size:30px;
            border-radius:10px 0 0 10px;
            border:1px solid rgba(227,227,227,1);
            border-right:none;
            box-shadow:0 0 0 rgba(0,0,0,0);
            -webkit-appearance:none;
            outline:none;
            background:#F6F7F8;
          }
          span{
            display:inline-block;
            width:39.9999%;
            height:84px;
            line-height:84px;
            border-radius:0 10px 10px 0;
            vertical-align:top;
            background:#D1D1D1;
            color:#fff;
            font-size:30px;
            text-align:center;
            /*border:1px solid rgba(227,227,227,1);
            border-left:none;*/
          }
        }
        .finish-btn{
          height:84px;
          line-height:84px;
          margin-top:32px;
          text-align:center;
          color:#fff;
          font-size:34px;
          border-radius:8px;
          background:rgba(23,62,143,0.5);
        }
        .success{
          background:rgba(23,62,143,1);
        }
      }
    }
  }
  .fixed-position{
    position:fixed;
  }
  .static-position{
    position:absolute;
  }

  .fade-enter-active, .fade-leave-active{
    /*opacity:1;
    background: rgba(7, 17, 27, 0.8);*/
    transition: all 0.5s;
    transform:translate(0, 0);
  }
  .fade-enter, .fade-leave-active{
    /*opacity:0;
    background:rgba(7, 17, 27, 0);*/
    transform: translate(0, 100%);
  }
  input::-webkit-input-placeholder{
    color: #B7C3D1;
    font-size:26px;
  }
</style>
<style>
  .cube-toast-tip{
    /*max-width:13em;*/
    font-size:28px;
    max-width:15.5em;
    line-height:40px;
  }
  .cube-toast.cube-popup {
    z-index: 10000!important;
  }
  .switch-btn .cube-switch .cube-switch-input{
    width:80px;
    height:46px;
  }
  .switch-btn .cube-switch .cube-switch-input:checked+.cube-switch-ui {
    border-color: #5872f1;
    background-color: #5872f1;
  }
  .switch-btn .cube-switch .cube-switch-ui {
    position: relative;
    display: block;
    width:80px;
    height:46px;
    box-sizing: content-box;
    border: 1px solid #e4e4e4;
    border-radius: 46px;
    background-color: #e4e4e4;
  }
  .switch-btn .cube-switch .cube-switch-ui:after, .switch-btn  .cube-switch .cube-switch-ui:before{
    border-radius: 46px;
  }
  .switch-btn .cube-switch .cube-switch-ui:after {
    width: 46px;
  }
  .switch-btn .cube-switch .cube-switch-input:checked+.cube-switch-ui:after {
    -webkit-transform: translateX(38px);
    transform: translateX(38px);
  }
  .picker-item{
    font-size:26px;
  }

  .picker-toolbar {
    height: 60px;
  }
  .mint-datetime-action{
    font-size:28px;
    line-height: 60px;
  }
  .picker-items >div:nth-child(3) {
    flex: 0!important;
  }
</style>
